local addonName = "PSLibSample";
local Addon = LibStub("AceAddon-3.0"):NewAddon(addonName, "AceEvent-3.0");
local PSO = LibStub("PSObjects-1.0");

--[[
local PSGUI = LibStub("PSGUI-1.0");
local PS = LibStub("PSLib-1.0");

local ACEGUI = LibStub("AceGUI-3.0");
------------------------------------------------------------
DEBUG_ENABLE(true);

local PaneBackdrop  = {
	bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
	edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
	tile = true, tileSize = 16, edgeSize = 16,
	insets = { left = 3, right = 3, top = 5, bottom = 3 }
}
local function GridTest()
	local group = PSGUI:Create("Group");
	group:SuspendLayout();
	group:SetSize(500,400);
	group:SetPoint("CENTER",100,0);
	group:SetBackgroundColor(0.5,0.5,0.5,0.5);
	--group:SetContainerType("Content");
	group:SetContainerLayoutSettings(
		{
			-- All container options
			columns = {"1*", "auto", 150},
			rows = {"1*", "auto", 50},
			cellSpacingH = 0,
			cellSpacingV = 	0,
			padding = PS:CreatePadding(0),
		}
	);
	
	local groupChild1 = PSGUI:Create("Group",group);	
	groupChild1:SetBackgroundColor(0.5, 0, 1, 0.2);
	groupChild1:SetLayoutSettings( { column = 1, row = 1} );
	
	local groupChild2 = PSGUI:Create("Group",group);
	groupChild2:SetBackgroundColor(0.5, 0.5, 0, 0.2);
	groupChild2:SetLayoutSettings( { column = 2, row = 2,} );
	
	local groupChild3 = PSGUI:Create("Group",group);
	groupChild3:SetBackgroundColor(0, 0.5, 0.5, 0.2);
	groupChild3:SetLayoutSettings( { column = 3, row = 3,} );
	
	group:Show();
	group:ResumeLayout();
	
end

local function WrapTest()
	local group = PSGUI:Create("Window");
	group:SuspendLayout();
	group:SetLayout("Wrap");
	
	group:SetSize(500,400);
	group:SetPoint("CENTER",100,0);
	group:SetBackgroundColor(0.5,0.5,0.5,0.5);
	
	group:SetContainerLayoutSettings(
		{
			-- All container options
			orientation = "horizontal", 
			flowDirectionMembers = "near2far",
			flowDirectionGroups = "near2far",
			--maxGroups = 2,
			padding = PS:CreatePadding(0),
		}
	);
	
	group:SetContainerType("Content");
	
	--for i=1,20 do
		local groupChild1 = PSGUI:Create("Group",group);	
		
		--group.container:EnableScroll("vertical",false);
		group.container:EnableScroll("horizontal",false);
		
		groupChild1:SetBackgroundColor(0.5, 0, 1, 0.2);
		groupChild1:SetDesiredSize(200,50)
		groupChild1:SetLayoutSettings( 
			{ 
				alignmentH = "center",				-- "string"(center|near|far|stretch)
				alignmentV = "center",				-- "string"(center|near|far|stretch)
				margin = PS:CreatePadding(10),
				order = 0,
			} 
		);

		local groupChild2 = PSGUI:Create("Group",group);
		groupChild2:SetBackgroundColor(0.5, 0.5, 0, 0.5);
		groupChild2:SetDesiredSize(100,75)
		groupChild2:SetLayoutSettings( 
			{ 
				alignmentH = "center",				-- "string"(center|near|far|stretch)
				alignmentV = "center",				-- "string"(center|near|far|stretch)
			} 
		);
		
		local groupChild3 = PSGUI:Create("Group",group);
		groupChild3:SetBackgroundColor(0.5, 0, 0, 0.2);
		groupChild3:SetDesiredSize(50,155)
		groupChild3:SetLayoutSettings( 
			{ 
				alignmentH = "far",				-- "string"(center|near|far|stretch)
				alignmentV = "center",				-- "string"(center|near|far|stretch)
				breakGroup = true,
			} 
		);
		
		local groupChild4 = PSGUI:Create("Group",group);
		groupChild4:SetBackgroundColor(0, 0.5, 0, 0.2);
		groupChild4:SetDesiredSize(125,25)
		groupChild4:SetLayoutSettings( 
			{ 
				alignmentH = "near",				-- "string"(center|near|far|stretch)
				alignmentV = "far",				-- "string"(center|near|far|stretch)
			} 
		);
	--end
	
	group:Show();
	
	
	group:ResumeLayout();
	
	
--	groupChild1:SetDesiredSize(800,50);
	
	--group:SetContainerType("Group");
end

local function PopupTest()
	local group = PSGUI:Create("Window");
	group:SuspendLayout();
	
	group:SetSize(500,400);
	group:SetPoint("CENTER",100,0);
	group:SetBackgroundColor(0.5,0.5,0.5,0.5);
	group:SetContainerLayoutSettings(
		{
			-- All container options
			columns = {"auto","auto"},
			rows = {"auto","auto"},
			cellSpacingH = 2,
		}
	);
	
	group:SetContainerType("Content");
	group:GetContainer():EnableScroll("horizontal",false);
	local popup = PSGUI:Create("Popup");
	popup:SetContainerLayoutSettings(
		{
			-- All container options
			columns = {"auto","auto"},
			rows = {"auto","auto"},
		}
	);
	
	local inbtn1 = PSGUI:Create("EditBox",popup);
	inbtn1:SetLayoutSettings( {column = 1, row = 1});
	inbtn1:SetBackgroundColor(1,0,1,0.3);
	
	local inbtn2 = PSGUI:Create("Button",popup);
	inbtn2:SetLayoutSettings( {column = 2, row = 2});
	inbtn2:SetBackgroundColor(1,1,0,0.3);
	inbtn2:AddCallback("OnClick", function(...)
		print("inbtn2 Click");
	end);
	
	local btn23 = PSGUI:Create("Button", group);
	btn23:SetDesiredSize(70,225);
	btn23:SetBackgroundColor(0,1,0,0.3);
	btn23:SetLayoutSettings(
		{
			column = 1,
			alignmentV = "near",
			alignmentH = "near",
		}
	);
	
	local btn = PSGUI:Create("Button",group);
	btn:SetBackgroundColor(0,0,1,0.3);
	btn:AddCallback("OnClick", function(...)
		popup:Show();
	end);
	btn:SetLayoutSettings(
		{
			column = 1,
			alignmentV = "near",
			alignmentH = "near",
		}
	);
	btn:SetDesiredSize(225,70);
	
	popup:SetWidth(300);
	popup:SetHeight(300);
	popup:SetPoint("TOPLEFT",btn.frame,"TOPRIGHT",0,0);
	popup:AssignPopupOwner(btn);
	
	group:Show();
	
	group:ResumeLayout();
	
end

local function ListViewTest()
	local group = PSGUI:Create("Window");
	group:SuspendLayout();
	
	group:SetSize(500,400);
	group:SetPoint("CENTER",100,0);
	group:SetBackgroundColor(0.5,0.5,0.5,0.5);
	group:SetContainerLayoutSettings(
		{
			-- All container options
			columns = {"auto"},
			rows = {"auto"},
		}
	);
	
	local listView = PSGUI:Create("ListView", group);
	listView:SetBackgroundColor(1,1,1,0.3);
	listView:SetDesiredSize(300, 300);
	
	group:Show();
	
	group:ResumeLayout();
	
end
]]
------------------------------------------------------------
------------------------------------------------------------
-- AceAddon implementation ---------------------------------
------------------------------------------------------------
function Addon:OnInitialize()
	--GridTest();
	--WrapTest();
	--PopupTest();
	--ListViewTest();
	--[[
	local dictionary = PSO:Create("Dictionary");
	dictionary:AddCallback("OnItemAdded", function(self, key, value)
		--print("OnItemAdded", self, key, value);
	end);
	dictionary:AddCallback("OnItemChanged", function(self, key, newValue, oldValue)
		--print("OnItemChanged", self, key, newValue, oldValue);
	end);
	
	dictionary:Add("test1",nil);
	dictionary:Add("test2",nil);
	dictionary:Add("test3","Hello");
	dictionary:Add("test4",{});
	dictionary:Add("test5", nil);
	for key, value in dictionary:Iterate() do
		print(key, value);
	end
	]]
	
	
	local list = PSO:Create("Collection", "List");
	list:CallbackAdd("OnItemAdded", function(self, index, value)
		print("OnItemAdded", self, index, value);
	end);
	list:CallbackAdd("OnItemRemoved", function(self, index, value)
		print("OnItemRemoved", self, index, value);
	end);
	list:CallbackAdd("OnItemChanged", function(self, index, newValue, oldValue)
		print("OnItemChanged", self, index, newValue, oldValue);
	end);
	
	list:AddHead(5);
	list:AddTail(nil);
	list:AddHead(nil);
	list:AddTail("Hello");
	list:AddHead({});
	list:RemoveAt(list:GetTailPosition());

	local pos = list:GetHeadPosition();
	
	while(pos:IsValid()) do
		print(pos:Next());
	end
	--print(list:GetHeadPosition());
	--print(list:GetTailPosition());
	--for key, value in list:Iterate() do
	--	print(key, value);
	--end	
	
end

function Addon:OnEnable()
end

function Addon:OnDisable()
end

------------------------------------------------------------
-- AceDB Callbacks implementation --------------------------
------------------------------------------------------------
function Addon:ProfileChanged()	
end

function Addon:ProfileReset()
end
